<?php
/*
 * Created on Jul 2, 2009
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
 $loader->requireOnce('includes/emrCore/GeneralEmrProcessor.class.php');
 $loader->requireOnce('includes/emrCore/PanelSelectBox.class.php');
 
 
 class C_GeneralEmr extends Controller {
 	
 	private $logger ;
 	
 	public function C_GeneralEmr() {
 		parent::Controller();
 		$this->logger = LoggerManager::getLogger('core.controllers.C_GeneralEmr');
 	}
 	
 	public function actionBuildSelectionPanelAjax() {
 		////Initial flow///
 		$requestedEmr = 0;
 		$recordId = 0;
 		$currDep = $this->_me->get_department_id();
 		
 		
 		/* case Except: map empty -> show error.
 		 * case 1: currDep != null > 0 and currDep in map
 		 *  case 1.1  $selectedEmr != null > 0 in map
 		 * 		-> build map + load emr -> set selection = (currDep, selectedEmr)
 		 *  case 1.2  $selectedEmr == null ==0 or not in map
 		 * 		-> build map + load default emr for currDep 
 		 * 			-> set selelection= (currDep, defaultEmr)
 		 *  
 		 * 
 		 * case 2 currDep != null > 0 and currDep not in map
 		 * 		-> build map + load the first one in map -> set selection(item.dep,item.erm)
 		 * case 3 currDep == null or 0
 		 *  case 3.1: selectedEmr == null or 0
 		 *  	-> build map + load the first one in map ->  set selection(item.dep,item.erm)
 		 *  case 3.2: selectedEmr != null and in map
 		 * 		-> build map + load the first map element contain selectedEmr
 		 *   	 	->set selection(item.dep,item.erm)
 		 *  
 		*/		
 		

 		if (isset($_GET['selectedEmr']) && $_GET['selectedEmr'] > 0) {
 			$requestedEmr = $_GET['selectedEmr']; 
 			//check this requested emr is exist in map or not			
 		} else {
 			//
 		}
 		if (isset($_GET['recordId']) && $_GET['recordId'] > 0) {
 			$recordId = $_GET['recordId']; 			
 		}
 		////////////
 		
 		$result = array();
 		
 		$processor = new GeneralEmrProcessor($this); 	 			
 		try { 			 		
 			$processor->initialProcessor($currDep, $requestedEmr); 	
 			$processor->setPanelBuilder(new PanelSelectBox());		 			
 			$result['content'] = $processor->buildSelectionPanel($recordId); 			  		
 		} catch (Exception $ex) { 			
 			$result['error']= L10nHelper::_('There is no medical record detail');
 			$this->logger->error($ex->getMessage()); 			
 		} 	
 		return json_encode($result);
 	} 	
 	
 	
 	public function actionLoadEmrAjax() {
 		$params = array();
 		$emrId = null;
 		if (isset($_GET['recordId'])) {
 			$params['recordId'] = $_GET['recordId'];		
 		}
 		if (isset($_GET['emrId'])) {
 			$emrId = $_GET['emrId'];
 		} 
 		
 		$processor = new GeneralEmrProcessor($this);
 		$result = array();
 		try {
 			$result['content'] = $processor->loadEmr($emrId, $params); 			
 		} catch (Exception $ex) {
 			$result['error']= L10nHelper::_('Loading requested medical record detail fail');
 			$this->logger->error($ex->getMessage()); 			 		
 		}
 		return json_encode($result); 		
 	}
 }
?>
